package jp.sinya.xml_parse;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.util.List;

public class Dom4JParse {
    public static final String xmlPath = "javademo/src/jp/sinya/person.xml";

    public void parse() {
        SAXReader saxReader = new SAXReader();
        try {
            Document document = saxReader.read(xmlPath);
            Element root = document.getRootElement();

            List<Element> elementList = root.elements("p");
            for (int i = 0; i < elementList.size(); i++) {
                Element name = elementList.get(i).element("name");
                System.out.println(name.getText());
            }
        } catch (DocumentException e) {
            e.printStackTrace();
        }

    }
}
